package com.zmj.mapstruct;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author zmj
 */
@Mapper(componentModel = "spring")
public interface UserCovertBasic {

    UserCovertBasic INSTANCE = Mappers.getMapper(UserCovertBasic.class);

    /**
     * 字段数量类型数量相同
     */
    UserVO1 userConvertVO1(User source);

    User userVO1ConvertUser(UserVO1 userVO1);

    List<UserVO1> userConvertVO1(List<User> source);


    /**
     * 字段数量类型相同,数量少
     */
    UserVO2 userConvertVO2(User source);

    /**
     * 转list
     */
    User userVO2ConvertUser(UserVO2 userVO2);


    /**
     * 映射字段名称不一致转换
     * <p>
     * 映射字段类型不一样指定通用转换器（部分类型会自动转换，参考官网）
     *
     * @param source
     * @return
     */
    @Mappings({
            @Mapping(source = "name", target = "nameStr"),
            @Mapping(source = "id", target = "idStr"),
            @Mapping(target = "updateTime", expression = "java(com.zmj.mapstruct.DateTransform.dateToStr(source.getUpdateTime()))")
    })
    UserVO3 userConvertVO3(User source);

}
